package com.javaweb.dao.impl;

import com.javaweb.model.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class CategoryDaoImpl implements com.javaweb.dao.CategoryDao {
    @Autowired
   JdbcTemplate jdbcTemplate;
    @Override
    public int insert(Category category) {

        // 检查 category 对象和类别名称是否为空


        // SQL 插入语句
        String sql = "insert into tb_category (name, `order`, parent_id, create_time, update_time) values (?, ?, ?, ?, ?)";

        jdbcTemplate.update(sql, category.getName(), category.getOrder(), category.getParentId(), category.getCreateTime(), category.getUpdateTime());
        // 返回值：如果插入成功，返回1；否则返回0
        return jdbcTemplate.update(sql, category.getName(), category.getOrder(), category.getParentId(), category.getCreateTime(), category.getUpdateTime());
    }

}
